//
//  CS_Page_TextView.m
//  Pods
//
//  Created by 网新中研 on 17/3/1.
//
//

#import "CS_Page_TextView.h"
#import "Common.h"
#import "CSConnector.h"

#define ALERT_TAG_DAIL_PHONE 1//打电话
#define ALERT_TAG_OPEN_WEBSIZE 2//打开网页

#define HEIGHT_PRELOAD_IMAGE 90 //预加载图片默认高度

#define CONTENT_WIDTH (kWindowW - 3 * CELL_RIGHT_MARGIN - CELL_TITLE_WIDTH)

@interface CS_Page_TextView()<UIAlertViewDelegate, UITextViewDelegate>

/**
 * 值标签
 */
@property (nonatomic, strong) UILabel *valueLabel;

/**
 * 点击按钮
 */
@property (nonatomic, strong) UIButton *clickButton;

@property (nonatomic, assign) BOOL isMulityLineRequired;

@property (nonatomic, strong) UIImageView *preloadImageView;



/********************自定义标签的处理***********************/
@property (nonatomic, strong) NSString *content;
@property (nonatomic, strong) UIFont *font;
@property (nonatomic, strong) UIColor *textColor;
@property (nonatomic, assign) BOOL isCustomerLabel;
@property (nonatomic, assign) NSTextAlignment textAlignment;



/********************输入编辑框***********************/
@property (nonatomic, assign) BOOL isEditEnable;
@property (nonatomic, copy) TextChangeBlock textChangedHandler;
@property (nonatomic, strong) UITextView *editTextView;

@end

@implementation CS_Page_TextView

-(NSInteger)viewType{
    return CSViewType_PageTextView;
}

-(void)setValue:(NSString *)value{
    super.value = value;
    _content = value;
    _dataValue = value;
    if (self.isEditEnable) {
        self.editTextView.attributedText = [self getAttributedText:value];
    }else{
        _dataValue = value;
        self.valueLabel.text = value;
        self.valueLabel.attributedText = [self getAttributedText:self.content];
    }
}

-(void)setDataValue:(NSString *)dataValue{
    _dataValue = dataValue;
    super.value = dataValue;
}

-(NSString *)value{
    return _content;
}

+(id)page_textView:(NSString *)title dataValue:(NSString *)dataValue{
    CS_Page_TextView  *page_textView = [CS_Page_TextView new];
    page_textView.title = title;
    page_textView.dataValue = dataValue;
    return page_textView;
}

+(id)page_textViewWithFont:(UIFont *)font textColor:(UIColor *)textColor content:(NSString *)content textAlignment:(NSTextAlignment )textAlignment{
    CS_Page_TextView  *page_textView = [CS_Page_TextView new];
    page_textView.content = content;
    page_textView.font = font;
    page_textView.textColor = textColor;
    page_textView.isCustomerLabel = YES;
    page_textView.textAlignment = textAlignment;
    return page_textView;
}

+(id)page_textViewForEdit:(UIFont *)font textColor:(UIColor *)textColor content:(NSString *)content textAlignment:(NSTextAlignment )textAlignment textChangedHandler:(TextChangeBlock)textChangedHandler{
    
    CS_Page_TextView  *page_textView = [CS_Page_TextView new];
    page_textView.content = content;
    page_textView.dataValue = content;
    page_textView.font = font;
    page_textView.textColor = textColor;
    page_textView.textAlignment = textAlignment;
    page_textView.textChangedHandler = textChangedHandler;
    page_textView.isEditEnable = YES;
    
    return page_textView;
}

-(instancetype)init{
    if (self = [super init]) {
        self.leftMargin = CELL_EDIT_RIGHT_MARGIN;
        self.rightMargin = CELL_EDIT_RIGHT_MARGIN;
    }
    return self;
}

-(void)refreshContent:(NSString *)content{
    self.dataValue = content;
    self.content = content;
    self.valueLabel.attributedText = [self getAttributedText:self.content];
}

-(void)refreshTextColor:(UIColor *)textColor{
    
    self.valueLabel.textColor = textColor;
    self.textColor = textColor;
    
}

-(void)refreshFont:(UIFont *)font{
    
    self.font = font;
    self.valueLabel.font = font;
    
}

-(void)setIsShowUnderLine:(BOOL)isShowUnderLine{
    
    _isShowUnderLine = isShowUnderLine;
    
    if (isShowUnderLine) {
        //设置段落属性
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 6.0;
        paragraphStyle.alignment = self.valueLabel.textAlignment;
        NSDictionary *attributes = @{
                                     NSFontAttributeName:self.valueLabel.font,
                                     NSParagraphStyleAttributeName:paragraphStyle,
                                     NSUnderlineStyleAttributeName:[NSNumber numberWithInteger:NSUnderlineStyleSingle],
                                     NSUnderlineColorAttributeName:self.underLineColor ? self.underLineColor : COLOR_THEME
                                     };
        self.valueLabel.attributedText = [[NSAttributedString alloc] initWithString:self.content ? self.content : @"" attributes:attributes];
    }else{
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = 6.0;
        paragraphStyle.alignment = self.valueLabel.textAlignment;
        NSDictionary *attributes = @{
                                     NSFontAttributeName:self.valueLabel.font,
                                     NSParagraphStyleAttributeName:paragraphStyle
                                     };
        self.valueLabel.attributedText = [[NSAttributedString alloc] initWithString:self.content ? self.content : @"" attributes:attributes];
    }
    
}

-(void)textViewDidBeginEditing:(UITextView *)textView{
    textView.layer.borderColor = COLOR_THEME.CGColor;
    textView.layer.borderWidth = 1.0;
}

-(void)textViewDidEndEditing:(UITextView *)textView{
    textView.layer.borderWidth = 0.0;
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    
    NSString *newString = [textView.text stringByReplacingCharactersInRange:range withString:text];
    
    self.isRefreshRequired = YES;
    self.content = newString;
    
    if (self.textChangedHandler) {
        self.textChangedHandler(textView);
    }
    
    return YES;
}

-(NSString *)previousProcess:(NSString *)dataValue{
    
    if ([self isNullOrEmpty:self.seperateKeyString]) {
        return dataValue;
    }
    
    if (![self isNullOrEmpty:self.seperateKeyString]) {
        dataValue = [dataValue replaceCharcter:self.seperateKeyString withCharcter:@"；"];
    }
    dataValue = [dataValue replaceCharcter:@";" withCharcter:@"；"];
    NSArray *itemArray = [dataValue componentsSeparatedByString:@"；"];
    NSMutableString *resultString = [NSMutableString new];
    if (itemArray.count > 1) {
        self.isMulityLineRequired = YES;
        for (int i = 0; i < itemArray.count; i++) {
            if (i==0) {
                
                [resultString appendString:[NSString stringWithFormat:@"[%d]  %@", i + 1, [self trimmingString:[itemArray objectAtIndex:i]]]];
            }else if (i==itemArray.count-1){
                [resultString appendString:[NSString stringWithFormat:@"\r\n[%d]  %@", i + 1, [self trimmingString:[itemArray objectAtIndex:i]]]];
            }else{
                [resultString appendString:[NSString stringWithFormat:@"\r\n[%d]  %@", i + 1, [self trimmingString:[itemArray objectAtIndex:i]]]];
            }
        }
    }else{
        self.isMulityLineRequired = NO;
        return dataValue;
    }
    
    return resultString;
}

-(NSString *)trimmingString:(NSString *)originalString{
    return [originalString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}

-(CGFloat)layoutView:(UIView *)superView primaryY:(CGFloat)primaryY{
    
    REMOVE_SUBVIEWS(self);
    
    if (self.isEditEnable) {
        return [self customerEditLabelLayout:superView priamaryY:primaryY];
    }else if (self.isCustomerLabel) {
        self.content = [self previousProcess:self.content];
        return [self customerLabelLayout:superView priamaryY:primaryY];
    }
    
    self.dataValue = [self previousProcess:self.dataValue];
    
    if (self.dataValue == nil
        && [CSBaseView preloadImage] != nil) {
        
        [self addSubview:self.preloadImageView];
        
        self.preloadImageView.frame = CGRectMake(11, primaryY, kWindowW - 22, HEIGHT_PRELOAD_IMAGE);
        [superView addSubview:self.preloadImageView];
        
        return primaryY + HEIGHT_PRELOAD_IMAGE;
    }
    
    CGFloat localY = 0;
    
    //值预处理
    if ([_dataValue isValidUrl]) {
        _valueLabel.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:FONT_SIZE_REM];
        
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@", _dataValue]];
        [attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, _dataValue.length)];
        self.valueLabel.attributedText = attributedString;
        
    }else{
        _valueLabel.text = _dataValue;
    }
    
    CGFloat titleWidth = [self estimateWidth:self.titleLabel.font content:_title];
    CGFloat contentWidth = [self estimateWidth:self.valueLabel.font content:_dataValue];
    
    if((titleWidth > CELL_TITLE_WIDTH)
       ||contentWidth > CONTENT_WIDTH
       ||self.isMulityLineRequired){
        //执行换行处理
        localY = [self mulitiLineLayout:localY primaryY:primaryY];
    }else {
        //执行单行处理
        localY = [self singleLineLayout:localY primaryY:primaryY];
    }
    
    //是否是可点击值，则附加上按钮
    if (self.clickButton) {
        self.valueLabel.textColor = COLOR_THEME;
        self.clickButton.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
        
        [self addSubview:self.clickButton];
    }
    
    [superView addSubview:self];
    
    [super layoutView:superView primaryY:primaryY];
    
    if (_preloadImageView != nil) {
        
        [superView addSubview:_preloadImageView];
        [self startHideImage];
        
    }
    
//    self.backgroundColor = [UIColor clearColor];
    
    return primaryY + localY + 5 + 5;
}

-(void)startHideImage{
    [UIView animateWithDuration:1 animations:^{
        _preloadImageView.layer.opacity = 0.0;
    } completion:^(BOOL finished) {
        [_preloadImageView removeFromSuperview];
        _preloadImageView = nil;
    }];
}

-(UITextView *)editTextView{
    if (_editTextView == nil) {

        _editTextView = [[UITextView alloc] init];
        _editTextView.delegate = self;
        _editTextView.backgroundColor = [UIColor clearColor];
//        _editTextView.adjustsFontForContentSizeCategory = NO;
        _editTextView.scrollEnabled = NO;
        
        _editTextView.font = self.font == nil ? self.editTextView.font : self.font;
        _editTextView.textColor = self.textColor == nil ? self.editTextView.textColor : self.textColor;
        _editTextView.textAlignment = self.textAlignment < 0 ? NSTextAlignmentLeft : self.textAlignment;
    }
    return _editTextView;
}

-(CGFloat)layoutViewForRefresh:(UIView *)superView primaryY:(CGFloat)primaryY{
    
    if (self.isRefreshRequired) {
        
        self.editTextView.frame = CGRectMake(CELL_EDIT_RIGHT_MARGIN,
                                             0,
                                             kWindowW - 2 * CELL_RIGHT_MARGIN,
                                             0);
        [self.editTextView sizeToFit];
        self.editTextView.frame = CGRectMake(CELL_EDIT_RIGHT_MARGIN,
                                             0,
                                             kWindowW - 2 * CELL_RIGHT_MARGIN,
                                             self.editTextView.frame.size.height);
        
        CGFloat needDataHeight = self.editTextView.frame.size.height + CELL_TOP_MARGIN;
        self.frame = CGRectMake(0, primaryY, kWindowW, needDataHeight);
        
        self.isRefreshRequired = NO;
        
        return primaryY + needDataHeight;
        
    }else{
        return [super layoutViewForRefresh:superView primaryY:primaryY];
    }
    
}

-(NSString *)content{
    if (_content == nil) {
        return @"";
    }
    return _content;
}

-(CGFloat)customerEditLabelLayout:(UIView *)superView priamaryY:(CGFloat)primaryY{
    
    REMOVE_SUBVIEWS(self);
    
    CGFloat needDataHeight = 0;
    
    self.editTextView.attributedText = [self getAttributedText:self.content];
    
    self.editTextView.frame = CGRectMake(CELL_EDIT_RIGHT_MARGIN - 3, 0, kWindowW - 2 * CELL_EDIT_RIGHT_MARGIN + 6, 0);
    [self.editTextView sizeToFit];
    self.editTextView.frame = CGRectMake(CELL_EDIT_RIGHT_MARGIN - 3, 0, kWindowW - 2 * CELL_EDIT_RIGHT_MARGIN + 6, self.editTextView.frame.size.height);
    
    needDataHeight = self.editTextView.frame.size.height + CELL_TOP_MARGIN;
    
    [self addSubview:self.editTextView];
    
    self.frame = CGRectMake(0, primaryY, kWindowW, needDataHeight);
    
    [superView addSubview:self];
    
    return primaryY + needDataHeight;
    
}

-(NSAttributedString *)getAttributedText:(NSString *)content{
    
    //设置段落属性
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    paragraphStyle.lineSpacing = 6.0;
    paragraphStyle.alignment = self.valueLabel.textAlignment;
    NSDictionary *attributes = @{
                                 NSFontAttributeName:self.valueLabel.font,
                                 NSParagraphStyleAttributeName:paragraphStyle
                                 };
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:(content ? content : @"") attributes:attributes];
    NSRange wholeRange = NSMakeRange(0, [attributedString length]);
    UIColor *color = self.textColor == nil ? self.editTextView.textColor : self.textColor;
    [attributedString addAttribute:NSForegroundColorAttributeName value:color range:wholeRange];
    
    [CSBaseView colorApplicationColoredString:attributedString];
    
    return attributedString;
    
}

/**
 * 自定义标签布局
 */
-(CGFloat)customerLabelLayout:(UIView *)superView priamaryY:(CGFloat)primaryY{
    
    self.valueLabel.font = self.font == nil ? self.valueLabel.font : self.font;
    self.valueLabel.textColor = self.textColor == nil ? self.valueLabel.textColor : self.textColor;
    self.valueLabel.textAlignment = self.textAlignment < 0 ? NSTextAlignmentLeft : self.textAlignment;
    self.valueLabel.attributedText = [self getAttributedText:self.content];
    self.valueLabel.frame = CGRectMake(self.leftMargin, 0, kWindowW - self.leftMargin - self.rightMargin, 0);
    [self.valueLabel sizeToFit];
    self.valueLabel.frame = CGRectMake(self.leftMargin, 0, kWindowW - self.leftMargin - self.rightMargin, self.valueLabel.frame.size.height);
    
    CGFloat needDataHeight = self.valueLabel.frame.size.height;
    
    [self addSubview:self.valueLabel];
    
    self.frame = CGRectMake(0, primaryY, kWindowW, needDataHeight);
    
    [superView addSubview:self];
    
    if (needDataHeight >= 30.0) {
        needDataHeight += 6.0;
    }
    
    return primaryY + needDataHeight + 6.0;
}

-(CGFloat)mulitiLineLayout:(CGFloat)localY primaryY:(CGFloat)primaryY{
    
    /******************************布局策略一******************************
     * 针对内容字数较多的, 用上下布局的方式
     */
    
    //标题
    self.titleLabel.text = [self isNullOrEmpty:_title] ? @"" : [NSString stringWithFormat:@"%@", _title];
    self.titleLabel.frame = CGRectMake(CELL_RIGHT_MARGIN, CELL_TOP_MARGIN, kWindowW - 2 * CELL_RIGHT_MARGIN, 40);
    [self.titleLabel sizeToFit];
    self.titleLabel.frame = CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y, self.titleLabel.frame.size.width + 20, self.titleLabel.frame.size.height + 6);
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.layer.borderColor = [UIColor colorFromHexCode:@"838082"].CGColor;
    self.titleLabel.layer.borderWidth = 0.8;
    CGFloat needTitleHeight = self.titleLabel.frame.size.height;
//    self.titleLabel.layer.cornerRadius = 3;
    self.titleLabel.layer.masksToBounds = YES;
    self.titleLabel.textColor = [UIColor colorFromHexCode:@"838082"];
//    self.titleLabel.textColor = [UIColor colorFromHexCode:@"b6b8bf"];
    needTitleHeight = needTitleHeight > CELL_LABLE_HEIGHT? needTitleHeight : CELL_LABLE_HEIGHT;
    [self addSubview:self.titleLabel];
    
    localY = 2 * CELL_TOP_MARGIN + needTitleHeight;
    
    //值
    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@", _dataValue]];
//    NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"        %@", _dataValue]];
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc]init];
    [paragraphStyle setLineSpacing:6.0];
    [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, _dataValue.length)];
    
    self.valueLabel.attributedText = attributedString;
    self.valueLabel.frame = CGRectMake(CELL_RIGHT_MARGIN, localY, kWindowW - 2 * CELL_RIGHT_MARGIN, 0);
    [self.valueLabel sizeToFit];

    CGFloat needDataHeight = self.valueLabel.frame.size.height;
    needDataHeight = needDataHeight > CELL_LABLE_HEIGHT ? needDataHeight : CELL_LABLE_HEIGHT;
    
    [self addSubview:self.valueLabel];
    
    //添加分割线
    localY = localY + needDataHeight;
    
    self.frame = CGRectMake(0 , primaryY, kWindowW, localY);
    
    return localY - 5;
}

-(CGFloat)singleLineLayout:(CGFloat)localY primaryY:(CGFloat)primaryY{
    
    /******************************布局策略二******************************
     * 针对内容字数较少的, 用左右布局的方式
     */
    
    self.titleLabel.textAlignment = NSTextAlignmentRight;
    
    //标题
    self.titleLabel.text = [self isNullOrEmpty:_title] ? @"" : [NSString stringWithFormat:@"%@", _title];
    self.titleLabel.frame = CGRectMake(CELL_RIGHT_MARGIN, CELL_TOP_MARGIN, CELL_TITLE_WIDTH, 0);
    [self.titleLabel sizeToFit];
    self.titleLabel.layer.borderColor = [UIColor colorFromHexCode:@"838082"].CGColor;
    self.titleLabel.layer.borderWidth = 0.8;
//    self.titleLabel.layer.cornerRadius = 3;
    self.titleLabel.layer.masksToBounds = YES;
    self.titleLabel.frame = CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y, self.titleLabel.frame.size.width + 20, self.titleLabel.frame.size.height + 6);
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
    self.titleLabel.textColor = [UIColor colorFromHexCode:@"838082"];
    
    CGFloat needTitleHeight = self.titleLabel.frame.size.height;
    needTitleHeight = needTitleHeight > CELL_LABLE_HEIGHT? needTitleHeight : CELL_LABLE_HEIGHT;
    [self addSubview:self.titleLabel];
    
    localY =  CELL_TOP_MARGIN + needTitleHeight;
    
    //值
    if ([_dataValue isValidUrl]) {
        NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc]initWithString:[NSString stringWithFormat:@"%@", _dataValue]];
        [attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:NSMakeRange(0, _dataValue.length)];
        self.valueLabel.attributedText = attributedString;
        _valueLabel.font = [UIFont fontWithName:@"MarkerFelt-Thin" size:FONT_SIZE_REM];
    }else{
        self.valueLabel.text = _dataValue;
    }
    self.valueLabel.frame = CGRectMake(2 * CELL_RIGHT_MARGIN + CELL_TITLE_WIDTH, CELL_TOP_MARGIN, kWindowW - 3 * CELL_RIGHT_MARGIN - CELL_TITLE_WIDTH, 0);
    [self.valueLabel sizeToFit];
    self.valueLabel.frame = CGRectMake(self.valueLabel.frame.origin.x, self.valueLabel.frame.origin.y, kWindowW - 3 * CELL_RIGHT_MARGIN - CELL_TITLE_WIDTH, self.titleLabel.frame.size.height);
    
    CGFloat needDataHeight = self.valueLabel.frame.size.height;
    needDataHeight = needDataHeight > CELL_LABLE_HEIGHT ? needDataHeight : CELL_LABLE_HEIGHT;
    
    [self addSubview:self.valueLabel];
    
    localY = localY > CELL_LABLE_HEIGHT ? localY:CELL_LABLE_HEIGHT ;
    
    localY += 5;
    self.frame = CGRectMake(0, primaryY, kWindowW, localY);
    
    self.valueLabel.textColor = COLOR_TEXT_2;
    
    return localY - 15;
}

#pragma mark --- 辅助方法
/**
 * 文本所需要的长度
 */
-(CGFloat)estimateWidth:(UIFont *)font content:(NSString *)content{
    
    CGFloat needLength = 0;
    
    needLength = [self estimateWith:content font:font height:CELL_LABLE_HEIGHT];
    
    return needLength;
    
}

#pragma mark --- 点击方法集合

/**
 * 打开网络
 */
-(void)openWebSite{
    
    [[CSConnector entrance] openWebPage:_dataValue];
    
    CSSelectableModel *model1 = [CSSelectableModel new];
    model1.code = 0;
    model1.name = @"是东方红是高科技高房价高复的工会经费开个会";
    
    CSSelectableModel *model2 = [CSSelectableModel new];
    model2.code = 0;
    model2.name = @"是东方红是高科技高房价高复的工会经费开个会";
    
    CSSelectableModel *model3 = [CSSelectableModel new];
    model3.code = 0;
    model3.name = @"是东方红是高科技高房价高复的工会经费开个会";
    
    CSSelectableModel *model4 = [CSSelectableModel new];
    model4.code = 0;
    model4.name = @"是东方红是高科技高房价高复的工会经费开个会";
    
    CSSelectableModel *model5 = [CSSelectableModel new];
    model5.code = 0;
    model5.name = @"是东方红是高科技高房价高复的工会经费开个会";
    
    CSSelectableModel *model6 = [CSSelectableModel new];
    model6.code = 0;
    model6.name = @"是东方红是高科技高房价高复的工会经费开个会";
    
    NSArray *selectItems = @[model1, model1, model1, model1, model1, model1, model1];
    
    CS_Pop_SingleSelectView *selectView1 = [CS_Pop_SingleSelectView pop_SingleSelectView:@"Model选择框" selectItems:selectItems selectHandler:^(NSInteger section, NSInteger index, NSString *selectString) {
        
    }];
//    [selectView1 popShow];
    
    CS_Pop_SingleSelectView *selectView = [CS_Pop_SingleSelectView pop_SingleSelectView:@"选择框" selectItems:@[@"选项1：塑料袋辅导=", @"选项2：山东矿机非关键非关鬼地方个非官方个非官方更丰富更对规范更大幅度发梵蒂冈的非官方发高规格键发动机赶紧回家", @"选项3：结合各款到发货挂号费可更何况", @"选项2：山东矿机非关键非关鬼地方个非官方个非官方更丰富更对规范更大幅度发梵蒂冈的非官方发高规格键发动机赶紧回家", @"选项3：结合各款到发货挂号费可更何况", @"选项3：上课和挂号费", @"选项3：交换机电话灰盒", @"选项3：发几个客户豆腐干豆腐干非官方发给发给发广告", @"选项3：京东方华国锋读后感发货快", @"选项3：计算导航过节费合格后", @"选项2：山东矿机非关键非关鬼地方个非官方个非官方更丰富更对规范更大幅度发梵蒂冈的非官方发高规格键发动机赶紧回家", @"选项3：结合各款到发货挂号费可更何况", @"选项3：司法机关很快就烦得很公积金", @"选项2：山东矿机非关键非关鬼地方个非官方个非官方更丰富更对规范更大幅度发梵蒂冈的非官方发高规格键发动机赶紧回家", @"选项3：结合各款到发货挂号费可更何况", @"选项3：法典化股份骨灰盒"] selectHandler:^(NSInteger section, NSInteger index, NSString *selectString) {
        
    }];
//    [selectView popShow];
    
    CSSelectableModel *model11 = [CSSelectableModel new];
    model11.code = @"11";
    model11.name = @"工具开发更疯狂";
    
    CSSelectableModel *model12 = [CSSelectableModel new];
    model12.code = @"12";
    model12.name = @"水电费大幅度发开发";
    
    CSSelectableModel *model13 = [CSSelectableModel new];
    model13.code = @"13";
    model13.name = @"热个人卡发广告";
    
    CSSelectableModel *model14 = [CSSelectableModel new];
    model14.code = @"14";
    model14.name = @"是大幅度发";
    
    CSSelectableModel *model111 = [CSSelectableModel new];
    model111.code = @"111";
    model111.name = @"后我个我就好了开个房回家了";
    
    CSSelectableModel *model112 = [CSSelectableModel new];
    model112.code = @"112";
    model112.name = @"干活如图和髋关节";
    
    CSSelectableModel *model113 = [CSSelectableModel new];
    model113.code = @"113";
    model113.name = @"你，你，不能餐扩";
    
    model11.subItems = @[model111, model112, model113, model14];
    
    selectItems = @[model11, model12, model13];
    
    CS_Pop_MultitpleSelectView *pop_MultitpleSelectView = [CS_Pop_MultitpleSelectView pop_multitpleSelectView:selectItems titleName:@"多选框" selectCompletedHandler:^(NSString *resultNames, NSString *resultCodes) {
        
    }];
    [pop_MultitpleSelectView popShow];
    
}

/**
 * 打电话
 */
-(void)dialPhoneNubmer{
    
    NSMutableString * str=[[NSMutableString alloc] initWithFormat:@"telprompt://%@",_dataValue];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:str]];
    return;
    
}

#pragma mark --- UIAlertViewDelegate

-(UIImageView *)preloadImageView{
    if (_preloadImageView == nil) {
        _preloadImageView = [[UIImageView alloc]initWithImage:[CSBaseView preloadImage]];
        _preloadImageView.frame = CGRectMake(11, 0, kWindowW - 22, 90);
    }
    return _preloadImageView;
}

- (UILabel *)valueLabel {
    if(_valueLabel == nil) {
        _valueLabel = [[UILabel alloc] init];
        _valueLabel.font = [UIFont systemFontOfSize:(FONT_SIZE_REM)];
        _valueLabel.numberOfLines = 0;
        _valueLabel.textAlignment = NSTextAlignmentLeft;
        _valueLabel.textColor = COLOR_TEXT_3;
    }
    return _valueLabel;
}

-(UIButton *)clickButton{
    if (_clickButton == nil) {
        
        if ([_dataValue isVAlidPhoneNumber]) {//电话号码的方式
            _clickButton = [[UIButton alloc]init];
            [_clickButton addTarget:self action:@selector(dialPhoneNubmer) forControlEvents:UIControlEventTouchUpInside];
            return _clickButton;
        }else if([_dataValue isValidUrl]){//网址的方式
            _clickButton = [[UIButton alloc]init];
            [_clickButton addTarget:self action:@selector(openWebSite) forControlEvents:UIControlEventTouchUpInside];
            return _clickButton;
        }
    }
    return _clickButton;
}


@end
